﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using Chefbook.DataObjects;
using NUnit.Framework;
using Chefbook.UserActions;
using Rhino.Mocks;
using Chefbook.ViewModels;


namespace UnitTests.UserActionsTests
{
    [TestFixture]
    public class RemoveIngredientActionFixture
    {
        private IUserAction action;
        private CategoryViewModel category;
        private RecipeViewModel recipe;
        private IngredientViewModel ingredient;
        
        [SetUp]
        public void Init()
        {
            category = new CategoryViewModel(new Category(null)) { Name = "root" };
            recipe = new RecipeViewModel(new Recipe(category.CategoryModel)) { Name = "MyRecipe" };
            ingredient = new IngredientViewModel(new Ingredient(recipe.RecipeModel)) { Name = "MyIngredient" };

            Assert.Contains(ingredient, recipe.Ingredients);

            action = new RemoveIngredientAction(ingredient, recipe);
        }

        [Test]
        public void DoActionTest()
        {
            action.DoAction();
            Assert.AreEqual(0, recipe.Ingredients.Count);
            Assert.False(recipe.Ingredients.Contains(ingredient),"Ingredient not removed from Recipe");
        }

        [Test]
        public void UndoActionTest()
        {
            action.DoAction();
            action.UndoAction();
            Assert.AreEqual(1, recipe.Ingredients.Count);
            Assert.True(recipe.Ingredients.Contains(ingredient), "Ingredient not restored to Recipe");
        }

        [Test]
        public void UndoActionWithoutDoingTest()
        {
            UserActionTestsHelper.UndoActionWithoutDoingTest(action);
        }

        [Test]
        public void UndoActionTwiceAfterDoingTest()
        {
            UserActionTestsHelper.UndoActionTwiceAfterDoingTest(action);
        }

        [Test]
        public void DoActionTwiceTest()
        {
            UserActionTestsHelper.DoActionTwiceTest(action);
        }

        [Test]
        public void ActionNameTest()
        {
            Assert.AreEqual(string.Format("Remove Ingredient '{0}' from Recipe '{1}'", ingredient, recipe), action.ToString());
        }


    }
}
